<?php
/**
 * spsNewsletter sendNewsletter View
 * 
 * @author Satyan Shah <joomlaDesign@modernbridge.com>
 * @link http://www.modernbridge.com
 * @license GNU/GPL
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.view' );


class spsNewslettersViewsendNewsletter extends JView
{

	function display($tpl = null)
	{
		// instantiate the model
		$newsletterModel =& $this->getModel();
		// call the get data function of our model to load the data into a  local object
		$newsletterData=$newsletterModel->getData();
		// call the image tag convert function of our model and overwrite the body variable in our local object
		$newsletterData->body=$newsletterModel->convertImgTags($newsletterData->body);
		// call the backgroiund image convert function of our model and overwrite the background property of tables
		$newsletterData->body=$newsletterModel->convertBackgroundTags($newsletterData->body);
		//get all of the available newsletters to populate select list
		$available_newsletters=$newsletterModel->getAllNewsletters();
		// create the toolbar for use in the view
		JToolBarHelper::title( JText::_( 'spsNewsletter Send Newsletter' ));
		JToolBarHelper::custom('send_all', 'send', '', 'Send Newsletter', false);
		JToolBarHelper::custom('send_test', 'forward', '', 'Send Test Message', false);
	
		// get parameters for displayin the form  
		$params=$newsletterModel->getComponentParameters();
		$fromName = $params->get('fromName');
		$fromEmail = $params->get('fromEmail');
   
		//create some js to submit our form if the user selects a different newsletter in the form
		$javascript = 'onchange="document.adminForm.submit();"';
    
		// load up data for use in the template
		$this->assignRef('lists', JHTML::_( 'select.genericlist', $available_newsletters, 'newsletterToSend',$javascript,'id','name',$newsletterData->id ));
		$this->assignRef('fromName',$fromName);
		$this->assignRef('fromEmail',$fromEmail);
 
		$this->assignRef('newsletterForPreview',$current_select_val);
		$this->assignRef('newsletterForPreviewBody',$newsletterData);
		$this->assignRef('subject',$newsletterData->name);

		parent::display($tpl);
	}

}
